package com.hfy.music.controller;

import com.hfy.model.dto.CommentDto;
import com.hfy.music.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.Result;

/**
 * @ author 韩
 * time: 2024/5/29 14:13
 */

@RestController
@RequestMapping("/comment")
@Tag(name = "对音乐的评论操作的接口类" ,description = "主要就是评论，crud评论的这一系列操作")
public class CommentController {

    @Autowired
    private CommentService commentService;


    @GetMapping("/show")
    @Operation(summary = "获取歌曲或评论对应的评论列表")
    @Parameters({@Parameter(name = "biz", description = "业务类型"),
            @Parameter(name = "bizId", description = "业务ID即为音乐Id或者评论Id"),
            @Parameter(name = "account", description = "账号")
    })
    public Result showComments(@RequestParam("biz") Integer biz,@RequestParam("bizId") Integer bizId,@RequestParam("account")  Long account) {
        return commentService.showComments(biz, bizId, account);
    }

    @PostMapping("/add")
    @Operation(summary = "评论歌曲")
    @Parameters({@Parameter(name = "account", description = "账号"),
            @Parameter(name = "biz", description = "业务类型"),
            @Parameter(name = "bizId", description = "业务Id"),
            @Parameter(name = "content", description = "评论的内容"),
            @Parameter(name = "commentTime", description = "评论的时间")}
    )
    public Result addComment(@RequestBody CommentDto dto) {
        Long account = dto.getAccount();
        Integer bizId = dto.getBizId();
        String content = dto.getContent();
        Integer biz = dto.getBiz();
//        LocalDateTime commentTime = dto.getCommentTime();
        return commentService.addComment(biz, account, bizId, content);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除歌曲的评论")
    @Parameters({@Parameter(name = "评论ID", description = "commentId")})
    public Result deleteComment(@PathVariable("id") Integer commentId){
        return commentService.deleteComment(commentId);
    }
}